package com.ssy.lingxi.member.merchant.entity;

import com.ssy.lingxi.member.merchant.handler.converter.JpaJsonToMapConverter;

import javax.persistence.*;
import java.io.Serializable;
import java.util.Map;
import java.util.Objects;

/**
 * 业务平台菜单页面按钮- 数据来源为PaaS平台会员设置
 * @author 万宁
 * @version 2.0.0
 * @date 2020-06-15
 */
@Entity
@Table(schema = "public", name = "ms_mc_menu_button", indexes = {@Index(name = "ms_mc_menu_button_parent_id_idx", columnList = "parentId")})
public class MenuButtonDO implements Serializable {
    private static final long serialVersionUID = 8227087191172605481L;

    @Id
    @GeneratedValue(strategy= GenerationType.SEQUENCE, generator="menu_button_seq")
    @SequenceGenerator(sequenceName="ms_mc_menu_button_seq", name="menu_button_seq",allocationSize = 1)
    private Long id;

    /**
     * PaaS配置的id
     */
    @Column
    private Long paasId;

    /**
     * 菜单的PaaS配置id
     */
    @Column
    private Long parentId;

    /**
     * 菜单项的Key
     */
    @Column(columnDefinition = "varchar(200)")
    private String key;

    /**
     * 按钮名称
     */
    @Column(columnDefinition = "varchar(50)", nullable = false)
    private String name;

    /**
     * 按钮Url
     */
    @Column(columnDefinition = "varchar(400)")
    private String url;

    /**
     * 按钮说明
     */
    @Column(columnDefinition = "varchar(100) default ''")
    private String remark;

    /**
     * 按钮编码
     */
    @Column(columnDefinition = "varchar(100)")
    private String code;

    /**
     * 按钮属性
     */
    @Convert(converter = JpaJsonToMapConverter.class)
    @Column(columnDefinition = "jsonb")
    private Map<String, Object> attrs;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Long getPaasId() {
        return paasId;
    }

    public void setPaasId(Long paasId) {
        this.paasId = paasId;
    }

    public Long getParentId() {
        return parentId;
    }

    public void setParentId(Long parentId) {
        this.parentId = parentId;
    }

    public String getKey() {
        return key;
    }

    public void setKey(String key) {
        this.key = key;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public String getRemark() {
        return remark;
    }

    public void setRemark(String description) {
        this.remark = description;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public Map<String, Object> getAttrs() {
        return attrs;
    }

    public void setAttrs(Map<String, Object> attrs) {
        this.attrs = attrs;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }

        if (o == null || getClass() != o.getClass()) {
            return false;
        }

        MenuButtonDO buttonDO = (MenuButtonDO) o;
        return Objects.equals(id, buttonDO.id);
    }

    @Override
    public int hashCode() {
        return id.hashCode();
    }
}
